package com.numbfish.ch01_ex03_a;

import com.numbfish.ch01_ex03_a.config.CustomConfig;
import com.numbfish.ch01_ex03_a.pojo.PersonA;
import com.numbfish.ch01_ex03_c.pojo.WheelInC;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

// @SpringBootTest
@Slf4j

public class Ch01Ex03ATestAppB {
    @Autowired
    private  ApplicationContext applicationContext;

    @Test
    void contextLoads() {
        log.info("applicationContext = {}",applicationContext);
    }
    @Test
    void beanCount(){
        // 用户未定义任何类时的bean个数为 springBoot2.7 : 139
        // 用户未定义任何类时的bean个数为 springBoot3   : 152
        log.info("applicationContext default bean count= {}",applicationContext.getBeanDefinitionNames().length);
    }


    void outputTheBeanFromContext(Class<?> clazz){
        // 用户未定义任何类时的bean个数为152
        log.info("applicationContext get a bean  {} === {}",clazz,applicationContext.getBean(clazz));
    }

    @Test
    void test1(){
        String[] names = applicationContext.getBeanNamesForType(PersonA.class);
        Arrays.stream(names).forEach(System.out::println);
    }

    @Test
    void test2(){
        ApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(CustomConfig.class);
        String[] names = annotationConfigApplicationContext.getBeanNamesForType(PersonA.class);
        Arrays.stream(names).forEach(System.out::println);
    }

    @Test
    void test3(){
        ApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(CustomConfig.class);
        String[] names = annotationConfigApplicationContext.getBeanNamesForType(PersonA.class);
        Arrays.stream(names).forEach(System.out::println);
    }


    @Test
    void test4(){
        WheelInC wheelInC = new WheelInC();
        System.out.println(wheelInC);
    }


}